package talk.View;

import android.app.Activity;
import android.view.View;
import android.widget.EditText;
import android.widget.ProgressBar;

import com.talk.debby.talk.R;

/**
 * Created by debby on 2018/3/27.
 * 描述:
 */

public class MainViewBuild implements View.OnClickListener {

    public interface Action {
        void bt_connect(String name, String password);

        void register();
    }

    public void setAction(Action action) {
        this.action = action;
    }

    private Activity activity;
    private Action action;
    //Text
    private EditText et_account;
    private EditText et_password;
    //加载动画
    private ProgressBar progressBar;


    public MainViewBuild(Activity activity) {
        this.activity = activity;
        initView();
    }

    private void initView() {
        activity.findViewById(R.id.bt_connect).setOnClickListener(this);
        activity.findViewById(R.id.tv_register).setOnClickListener(this);
        //输入框
        et_account = activity.findViewById(R.id.et_account);
        et_password = activity.findViewById(R.id.et_password);
        //加载动画
        progressBar = activity.findViewById(R.id.progressBar);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_connect:
                action.bt_connect(et_account.getText().toString(),
                        et_password.getText().toString());
                break;
            case R.id.tv_register:
                action.register();
                break;
        }
    }

    //初始化账号
    public void setData(String name) {
        et_account.setText(name);
    }

    public void showProgressBar() {
        progressBar.setVisibility(View.VISIBLE);
    }

    public void dismissProgressBar() {
        progressBar.setVisibility(View.GONE);
    }
}
